Skip to content

process: improve error message when cwd is deleted#60935

Closed
JBR-0100 wants to merge 2 commits into
nodejs:mainfrom
JBR-0100:fix/process-cwd-error-message
Closed

process: improve error message when cwd is deleted#60935
JBR-0100 wants to merge 2 commits into
nodejs:mainfrom
JBR-0100:fix/process-cwd-error-message

Conversation

@JBR-0100

@JBR-0100 JBR-0100 commented Dec 2, 2025

Copy link
Copy Markdown

Description

When process.cwd() is called after the current working directory has been deleted, the error message was unclear and showed internal implementation details.

Problem

Before:

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:142:28)

Issues:

  • ❌ Shows "uv_cwd" (internal implementation detail)
  • ❌ Doesn't clearly indicate the failure is from process.cwd()
  • ❌ Doesn't explain why it failed

Solution

After:

Error: process.cwd() failed: current working directory no longer exists
    at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:145:13)

Improvements:

  • ✅ Clearly mentions process.cwd()
  • ✅ Explains the likely cause (directory deleted)
  • ✅ Maintains error code (ENOENT) for programmatic handling

Changes

  • lib/internal/bootstrap/switches/does_own_process_state.js: Added try-catch to wrappedCwd() to enrich error message
  • test/known_issues/test-cwd-enoent-file.js: Updated test to expect new error message
  • test/parallel/test-process-cwd-deleted-dir.js: Added new test for improved error message

Fixes

Fixes: #57045

Checklist

  • Tests included
  • Error code preserved for backward compatibility
  • Documentation not needed (error message improvement)

TextDecoder was incorrectly using the Latin-1 decoder for Windows-1252
encoding, which caused bytes in the range 0x80-0x9F to be decoded
incorrectly. These bytes have specific character mappings in Windows-1252
(e.g., 0x92 → U+2019 ') but are undefined in ISO-8859-1 (Latin-1).

This commit adds a proper Windows-1252 decoder with a character mapping
table for the 32 special characters in the 0x80-0x9F range, following
the WHATWG Encoding Standard.

Fixes: nodejs#56542
When process.cwd() is called after the current working directory has
been deleted, the error message was unclear and showed internal
implementation details (uv_cwd).

This commit improves the error message to clearly indicate that
process.cwd() failed and explains the likely cause (directory no
longer exists).

Before:
  Error: ENOENT: no such file or directory, uv_cwd

After:
  Error: process.cwd() failed: current working directory no longer exists

The error code (ENOENT) is preserved for programmatic error handling.

Fixes: nodejs#57045
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Dec 2, 2025
@aduh95

aduh95 commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

A lot of unrelated changes, a PR description that looks LLM-generated, there's already an open PR (#57184) that better addresses the linked issue. Closing.

@aduh95 aduh95 closed this Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process.cwd() fails in a not usefully descriptive way

3 participants